﻿<%@ page import="com.cai.dao.MsgDao" %>
<%@ page import="com.cai.dao.impl.MsgDaoImpl" %>
<%@ page import="java.util.List" %>
<%@ page import="com.cai.entity.Msg" %>
<%@ page import="java.util.Objects" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
    boolean isExist = false;
    //获取当前用户
    String user = (String) session.getAttribute("user");
    request.setAttribute("user", user);
    //获取消息
    MsgDao msgDao = new MsgDaoImpl();
    //查看消息中是否有当前用户
    List<Msg> list = msgDao.allMsg();
    for (Msg msg : list) {
        if (Objects.equals(msg.getMsg_sendUser(), user) || Objects.equals(msg.getMsg_returnUser(), user)) {
            isExist = true;
        }
    }
    request.setAttribute("isExist", isExist);
    request.setAttribute("msgList", list);
%>
<head>
    <title>用户留言</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <link href="style/adminStyle.css" rel="stylesheet" type="text/css"/>
    <script src="js/jquery.js"></script>
    <script src="js/public.js"></script>
</head>
<body>
<div class="wrap">
    <div class="page-title">
        <span class="modular fl"><i class="user"></i><em>用户留言</em></span>
    </div>
    <table class="list-style Interlaced">
        <tr>
            <th>序号</th>
            <th>发送者姓名</th>
            <th>留言时间</th>
            <th>留言内容</th>
            <th>回复者姓名</th>
            <th>回复时间</th>
            <th>回复内容</th>
            <th>操作</th>
        </tr>
        <c:forEach varStatus="status" items="${requestScope.msgList}" var="msg">
            <c:if test="${msg.msg_sendUser==user || msg.msg_returnUser==user}">
                <tr>
                    <td class="center">${status.count}</td>
                    <td id="SendUser" class="center">${msg.msg_sendUser}</td>
                    <td id="SendDate" class="center">${msg.msg_sendDate} ${msg.msg_sendTime}</td>
                    <td id="SendTime" class="center" hidden>${msg.msg_sendTime}</td>
                    <td id="SendText" class="center"
                        style="width:400px;height:50px;overflow:scroll;overflow-x:hidden;">${msg.msg_sendText}</td>
                    <td class="center">${msg.msg_returnUser}</td>
                    <td class="center">${msg.msg_returnDate} ${msg.msg_returnTime}</td>
                    <td style="width:400px;height:50px;overflow:scroll;overflow-x:hidden;"
                        class="center">${msg.msg_returnText}</td>
                    <td class="center">
                        <a id="return_message" class="inline-block" title="回复"><img src="images/icon_title.gif"/></a>
                    </td>
                </tr>
            </c:if>
        </c:forEach>
    </table>
    <!-- BatchOperation -->
    <div style="overflow:hidden;">
        <!-- turn page -->
        <div class="turnPage center fr">
            <a>第一页</a>
            <a>1</a>
            <a>最后一页</a>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function () {
        // href="reply_message_return.jsp"
        $("[id=return_message]").click(function () {
            //获取日期
            var date = $(this).parent().parent().find("#SendDate").text();
            //获取时间
            var time = $(this).parent().parent().find("#SendTime").text();
            //获取发送者
            var sendUser = $(this).parent().parent().find("#SendUser").text();
            //获取发送消息
            var sendText=$(this).parent().parent().find("#SendText").text();
            $.ajax({
                url: "/cai/returnMessage",
                type: "get",
                data: {
                    "send_date": date,
                    "send_time": time,
                    "send_user": sendUser,
                    "send_text": sendText
                },
                success: function (data) {
                    location.href = "reply_message_return.jsp"
                }
            })
        })
    })
</script>
</body>
</html>